﻿using System;
using System.Collections.Generic;
using System.Linq;
using Database;

namespace DoMain.SetDomain
{
    public class PasswordSetDomain
    {
        readonly DatabaseInfo _dbInfo = new DatabaseInfo();

        /// <summary>
        /// 根据系统参数中的用户名查询该用户的密码
        /// </summary>
        /// <returns></returns>
        public string PasswordQuery()
        {
            string sql = string.Format("SELECT t1.PASSWORD from USERS t1 WHERE t1.NAME = '{0}' ", DatabaseInfo.UserName);
            List<string> passWords = _dbInfo.ColumnDataQuery(sql, "PASSWORD");
            return passWords.Count == 0 ? null : passWords.First();
        }

        /// <summary>
        /// 修改系统登录用户的密码
        /// </summary>
        /// <param name="newPassword"></param>
        /// <returns></returns>
        public string AlterPassword(string newPassword)
        {
            string sql = string.Format("UPDATE  USERS set PASSWORD = '{0}' WHERE NAME='{1}'", newPassword,
                DatabaseInfo.UserName);
            _dbInfo.SqlOperator(sql);
            return "修改成功。";
        }
    }
}
